import 'package:flutter/foundation.dart';

class UrlConfig {
  // This is used by upload package.
  // We need to check and refresh the token if it can.
  // Remember to set this url as isFullyAuthenticated() in spring security rest.
  // We are making a http get request to this url before upload.
  // It's the easy way to do the auto-refresh for upload.
  static String _tokenCheckUrl = '/tokenCheck';

  // Starting with Android API 28 and iOS 9, these platforms disable insecure HTTP connections by default.
  // With this change Flutter also disables insecure connections on mobile platforms. Other platforms (desktop, web, etc) are not affected.
  // https://flutter.dev/docs/release/breaking-changes/network-policy-ios-android
  //
  // Changes the local IP address to yours and makes sure your mobile device is connecting to the same network with PC when you are debugging.
  static String _apiHostBaseUrl =
      kReleaseMode ? 'https://zuiwen.cn' : 'http://192.168.2.56:8080';

  static String _apiHttpBaseUrl =
      kReleaseMode ? '/138090/family-expense/api' : '/family-expense/api';

  static String get tokenCheckUrl => _tokenCheckUrl;
  static String get apiHostBaseUrl => _apiHostBaseUrl;
  static String get apiHttpBaseUrl => _apiHttpBaseUrl;

  static void setUrls({
    String? tokenCheckUrl,
    String? apiHostBaseUrl,
    String? apiHttpBaseUrl,
  }) {
    if (tokenCheckUrl != null) {
      _tokenCheckUrl = tokenCheckUrl;
    }

    if (apiHostBaseUrl != null) {
      _apiHostBaseUrl = apiHostBaseUrl;
    }

    if (apiHttpBaseUrl != null) {
      _apiHttpBaseUrl = apiHttpBaseUrl;
    }
  }
}
